// miniprogram/pages/service/service.js
const db=wx.cloud.database()
Page({
  data: {
    // name:'',
    time: 30 * 60 * 60 * 1000,
    timeData: {},
    index:0,
    autoplay:true,
    duration:1000,
    interval:3000,
    indicatorDots:false,
    search: [],
    serch:true,
    cancle:false,
    showbox:true,
    value:'',
    rippleStyle:'',
  },
  onChange(e) {
    this.setData({
      timeData: e.detail
    });
    this.setData({
      value: e.detail
    });
  },
  onCancel(){
    this.setData({
      serch:true,
      cancle:false,
      showbox:false,
      value:""
    })

  },
  
  onClick:function(event) {
    this.setData({
      showbox:false,
      value:""
    })
  },
  onSearch:function(event) {
    // Toast('搜索' + this.data.value);
     let that=this
    console.log(event.detail)
    if(that.data.search==""){
      db.collection('seckill').where({
      name: event.detail
    }).get({
      success: function(res) {
        that.setData({
          search: res.data,
        })
        switc = false
        console.log('搜索成功', that.data.search)
        console.log('第一次'+switc)
         //第二次搜索
   if(that.data.search==""){
    db.collection('exchangeNV').where({
   name: event.detail
 }).get({
   success: function(res) {
     that.setData({
       search: res.data,
     })
     switc = false
 console.log('搜索成功', that.data.search)
 console.log('第二次' + switc)
 //第三次搜索
 if(that.data.search==""){
     db.collection('exchangeNan').where({
   name: event.detail
 }).get({
   success: function(res) {
     that.setData({
       search: res.data,
     })
     switc = false
 console.log('搜索成功', that.data.search)
 console.log('第三次' + switc)
 //第四次搜索
  if(that.data.search==""){
    db.collection('snacks').where({
   name: event.detail
 }).get({
   success: function(res) {
     that.setData({
       search: res.data,
     })
   }
 })
 switc = false
 console.log('搜索成功', that.data.search)
 console.log('第四次' + switc)
 if (that.data.search == "") {
   wx.showToast({
     title: '未找到服务',
     icon: "none"
   })
 }
}
   }
 })
 
 }
     
   }
 })
 
  }
      }
    })   
   
   // }
 // }
}
    
  },
  // imageChange:function(e){
  //   var index=e.detail.current;
  //   var length=this.data.imgUrls.length;
  //   // console.log(length)
  //   console.log(index);
  //   if(index==0){
      
  //     this.setData({
  //       duration:1000,
  //       interval:3000
  //     })
      
  //   }
  //   if(index==length-1){
  //     index=0;
  //     this.setData({
  //       duration:1,
  //       interval:3000,
  //       index:index
  //     })
  //   }

  // },

  containerTap: function (res) {
    var k=this
      var x = res.touches[0].pageX;
      var y = res.touches[0].pageY+90 ;
      this.setData({
        rippleStyle: 'top:' + y + 'px;left:' + x + 'px;-webkit-animation: ripple 0.4s linear;animation:ripple 0.4s linear;'
      });
      setTimeout(function() {
        k.setData({
          rippleStyle: ''
        })
      }, 400)
  },


  

  onLoad: function (options) {
    db.collection('seckill').get().then(res=>{
      this.setData({
        seckill: res.data
      })
    })
    db.collection('exchangeNV').get().then(res=>{
      this.setData({
        exchangeNV: res.data
      })
    })
    db.collection('exchangeNan').get().then(res=>{
      this.setData({
        exchangeNan: res.data
      })
    })
    db.collection('snacks').get().then(res=>{
      this.setData({
        snacks:res.data
      })
    })
    db.collection('ADvertisement').get().then(res=>{
      this.setData({
        imgUrls:res.data
      })
    })
    

  }
 
});